/*
************************************************************************************************************************************
*                                          GPRS DATA TRANSMISSION SERVICE 
*                                                  BASE ON PROTOCOL
*                                <<DATA TRANSMISSION PROTOCO V1.0 update20120801>>
*                                       (c) Copyright 2012 all right reserved
************************************************************************************************************************************
*
* Filename      : CommInterface.h
* Version       : V1.0.1
* Programmer    : Z
* Date          : 2013-05-25
************************************************************************************************************************************
*/

#ifndef _COMM_INTERFACE__H_
#define _COMM_INTERFACE__H_

#include "BasicTypeDef.h"
#include "includes.h"

typedef struct{
    T08U     Rs232[4];	    
    T08U     Rs485[4];	
    T32U     MsgTimout;
    T08U     NetIP[4];	
    T08U     NetPORT[4];	
    T08U     NetMASK[4];
    T08U     NetGATE[4];
    T08U     NetMAC[8];
    T32U     ServIP;		/* host bytes order */
    T32U     ServPORT;		/* host bytes order */
    T08U     Heartbeat[4];		/* host bytes order */
    T32U     TEMP;
    T32U     crc;    			/* WARNING:::the CRC must be the last two element!!!! */
}COMMCFG;

typedef enum{
    COMM_CHANNEL_RS232          = (T32U)0,
    COMM_CHANNEL_RS485          = (T32U)1,
    COMM_CHANNEL_ETH0_TCP_SER   = (T32U)2,
    COMM_CHANNEL_ETH1_UDP_SER   = (T32U)3,
    COMM_CHANNEL_ETH2_TCP_CLI   = (T32U)4,
    COMM_CHANNEL_USBDRIVE       = (T32U)5
}COMMCHL;
/*
************************************************************************************************************************
*                                                   configuration
************************************************************************************************************************
*/

#define MAX_MSG_SIZE                   1048
#define MIN_MSG_SIZE                   20
extern COMMCHL                         gCommWay;
extern T08U                           *prxbuf;

#if (defined USE_UDP_TCP_NET) || (defined USE_RS232_RS485)
extern T08U                            rxbuffer[];
#endif

#if (defined USE_UDP_TCP_NET) 
extern T08U                            udpbuffer[];
#endif

extern T32U                            rxsize;
extern OS_EVENT * CommRxMsgSem;
extern OS_EVENT * USBHRxMsgSem;
extern const T08U FrameHeader[];

/*
************************************************************************************************************************
*                                                   be care
************************************************************************************************************************
*/
#define MIN_PROTO_MSG_SIZE                     24
/*
************************************************************************************************************************
*                                                   declare
************************************************************************************************************************
*/

T32S CommInit     (COMMCFG *p);
T32S CommTxMessage(T08U * msg,T32U size);
T32S CommRxMessage(T08U **msg,T32U max_msg_size,T32U TimeOutMs);

#ifdef USE_UDP_TCP_NET
void     UdpServTask  (void *p_arg);
#endif
/*
************************************************************************************************************************
*                                                   END
************************************************************************************************************************
*/
#endif
